package com.example.sport;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    EditText etPersonName,etPassword;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        etPersonName = findViewById(R.id.etPersonName);
        etPassword = findViewById(R.id.etPassword);

        final String presetUsername = "admin";
        final String presetPassword = "123";

        Button loginButton = findViewById(R.id.btnLogin);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取用户输入的账号和密码
                String username = etPersonName.getText().toString();
                String password = etPassword.getText().toString();

                // 比较账号和密码是否与预设值匹配
                if (username.equals(presetUsername) && password.equals(presetPassword)) {
                    // 登录成功
                    Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    intent = new Intent(MainActivity.this, EntryActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    // 登录失败
                    Toast.makeText(MainActivity.this, "账号或密码错误", Toast.LENGTH_SHORT).show();
                    etPersonName.setText("");
                    etPassword.setText("");
                }
            }
        });
    }
}